package com.example.certificate.service.impl.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.certificate.entity.SysResource;
import com.example.certificate.entity.SysRouterAuth;
import com.example.certificate.mapper.SysRouterAuthMapper;
import com.example.certificate.service.SysResourceService;
import com.example.certificate.service.SysRouterAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import sun.reflect.generics.tree.Tree;

import javax.annotation.Resource;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hao
 * @since 2022-02-16 13:03:10
 */
@Service
public class SysRouterAuthServiceImpl extends ServiceImpl<SysRouterAuthMapper, SysRouterAuth> implements SysRouterAuthService {

    @Resource
    private SysRouterAuthMapper sysRouterAuthMapper;

    @Autowired
    private SysResourceService resourceService;

    @Override
    public List<SysRouterAuth> setRouterAuth(List<String> auth, String routerId) {
        List<SysRouterAuth> authList = new LinkedList<>();
        auth.forEach(item ->{
            SysRouterAuth sysRouterAuth = new SysRouterAuth();
            sysRouterAuth.setAuth(item);
            sysRouterAuth.setRouterId(routerId);
            authList.add(sysRouterAuth);
        });
        return authList;
    }

    @Override
    public List<String> getRouterAuth(String routerId) {
        List<SysRouterAuth> authList = sysRouterAuthMapper.selectList(new QueryWrapper<SysRouterAuth>().eq("router_id_", routerId));
        return authList.stream().map(SysRouterAuth::getAuth).collect(Collectors.toList());
    }

}
